
var ctx = ctx;
var patientId = $("#patientIdVal").val();
var visitId = $("#visitIdVal").val();
var clinicId = '';
$(function(){
    loadDiv('applyListDiv',ctx+'/blood/bloodApply/list?patientId='+patientId+'&visitId='+visitId+'&clinicId='+clinicId);
});

function bloodApplyClick(applyId){
    $("input:radio[value="+applyId+"]").prop("checked",true);
    loadDiv('capacityListDiv',ctx+'/blood/bloodCapacity/list?applyId='+applyId);
}

function loadApplyFormDiv(){
    $("#applyListDiv").attr("class","col-lg-6 panel");
    $("#applyFormDiv").show('normal');
    loadDiv('applyFormDiv',ctx+'/blood/bloodApply/form?patientId='+patientId+'&visitId='+visitId+'&clinicId='+clinicId);
}

/**
 * 打印用血申请
 */
function printBloodApply(applyNum){
    printPdf(ctx+'/blood/bloodApply/printBloodApply?applyNum='+applyNum);
}

function closeApplyFormDiv(){
    $("#applyListDiv").attr("class","col-lg-12 panel");
    $("#applyFormDiv").hide();
}

function loadCapacityFormDiv(){
    var val=$('input:radio[name="bloodApplyId"]:checked').val();
    if(val!=null){
        var status = $("#contentTable .table-selected").find("td").eq(6).find("input").val();
        if(status==0 || status=='0'){
            $("#capacityListDiv").attr("class","col-lg-8 panel");
            $("#capacityFormDiv").show('normal');
            loadDiv('capacityFormDiv',ctx+'/blood/bloodCapacity/form?patientId='+patientId+'&visitId='+visitId+"&applyId="+val);
        }else {
            toastr.info("用血申请已配血或已输血，不能进行添加操作");
        }

    }else{
        toastr.error("请先选择用血申请主记录信息");
    }

}
function closeCapacityFormDiv(){
    $("#capacityListDiv").attr("class","col-lg-12 panel");
    $("#capacityFormDiv").hide();
}

/**
 * @param divId
 * @param formId
 * @param url
 * @param hrefUrl
 * @param fun 隐藏表单方法
 * @returns {boolean}
 */
function formSaveLoadDiv(divId,formId,url,hrefUrl,fun){
    if($('#'+formId).parsley().validate()){
        setTimeout(saveForm(divId,formId,url,hrefUrl,fun),300);
    }
    return false;
}


function saveForm(divId,formId,url,hrefUrl,fun){
    if(flag){
        flag=false;
        formSubmitInput(formId);
        $("#"+formId+" input,#"+formId+" select").removeAttr("disabled");
        $.ajax({
            type: "POST",
            data:$("#"+formId).serialize(),
            url: url,
            dataType: "json",
            success: function (data) {
                if (data.code == "success") {
                    toastr.success(data.data);
                    fun();
                    loadDiv(divId,hrefUrl);
                } else {
                    flag=true;
                    toastr.error(data.data);
                }
            },
            error: function(data) {
                toastr.error('网络连接错误,请检查网络');
                flag=true;
            }
        });
    }
    return false;
}

/**
 * 查看方法
 * @param divId
 * @param url
 */
function loadShowDiv(divId,url){
    $("#applyListDiv").attr("class","col-lg-6 panel");
    $("#applyFormDiv").show('normal');
    loadDiv(divId,url);
}






